package cn.zyq.ykb.service.tk.impl;

import cn.zyq.ykb.beans.user.User;
import cn.zyq.ykb.system.common.BaseService;
import com.github.pagehelper.PageHelper;
import cn.zyq.ykb.system.ry.util.SecurityUtils;
import cn.zyq.ykb.mapper.tk.FeedBackMapper;
import cn.zyq.ykb.beans.tk.FeedBack;
import cn.zyq.ykb.service.tk.FeedBackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.zyq.ykb.system.common.PageParam;
import com.github.pagehelper.PageInfo;


import java.time.LocalDateTime;
import java.util.UUID;
import java.util.List;

/**
 * 反馈Service业务层处理
 *
 * @author SystemAuth
 * @date 2023-10-20
 */
@Service
public class FeedBackServiceImpl  extends BaseService implements FeedBackService {

    @Autowired
    private FeedBackMapper feedBackMapper;

    /**
     * 查询反馈
     *
     * @param feedBackID 反馈主键
     * @return 反馈
     */
    @Override
    public FeedBack selectFeedBackByFeedBackID(Integer feedBackID) {
        FeedBack feedBack = feedBackMapper.selectByPrimaryKey(feedBackID);
        if (feedBack.getDeleted() == 1) {
            return null;
        }
        return feedBack;
    }

    /**
     * 查询反馈
     *
     * @param serviceID 业务ID
     * @return 反馈
     */
    @Override
    public FeedBack selectFeedBackByServiceID(String serviceID) {
        FeedBack param = new FeedBack();
        param.setDeleted(0);
        param.setServiceID(serviceID);
        return this.feedBackMapper.selectOne(param);
    }

    /**
     * 查询反馈列表
     *
     * @param pageParam
     * @return 反馈
     */
    @Override
    public PageInfo<FeedBack> selectFeedBackList(PageParam pageParam) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        pageParam.getKv().put("deleted", 0);
        List<FeedBack> list = this.feedBackMapper.list(pageParam.getKv());
        return new PageInfo<>(list);
    }

    /**
     * 查询反馈列表
     *
     * @param pageParam
     * @return 反馈
     */
    @Override
    public List<FeedBack> selectFeedBackAllList(PageParam pageParam) {
        pageParam.getKv().put("deleted", 0);
        return this.feedBackMapper.list(pageParam.getKv());
    }
    /**
     * 新增反馈
     *
     * @param param 反馈
     * @return 结果
     */
    @Override
    public int insertFeedBack(FeedBack param) {
        this.setCreateBaseData(param, new User());
        return this.feedBackMapper.insertSelective(param);
    }

    /**
     * 修改反馈
     *
     * @param param 反馈
     * @return 结果
     */
    @Override
    public int updateFeedBack(FeedBack param) {
        this.setUpdateBaseData(param, new User());
        return this.feedBackMapper.updateByPrimaryKeySelective(param);
    }

    /**
     * 批量删除反馈
     *
     * @param feedBackIDs 需要删除的反馈主键
     * @return 结果
     */
    @Override
    public int deleteFeedBackByFeedBackIDs(Integer[] feedBackIDs) {
        int i = 0;
        for (Integer feedBackID : feedBackIDs) {
            i += this.deleteFeedBackByFeedBackID(feedBackID);
        }
        return i;
    }

    /**
     * 删除反馈信息
     *
     * @param feedBackID 反馈主键
     * @return 结果
     */
    @Override
    public int deleteFeedBackByFeedBackID(Integer feedBackID) {
        FeedBack feedBack = this.selectFeedBackByFeedBackID(feedBackID);
        if (feedBack == null) {
            return 0;
        } else {
            FeedBack storeInfo = new FeedBack();
            storeInfo.setFeedBackID(feedBackID);
            storeInfo.setDeleted(1);
            storeInfo.setUpdateTime(LocalDateTime.now());
            this.feedBackMapper.updateByPrimaryKeySelective(storeInfo);
            return 1;
        }
    }
}
